<template>
	<div class="bgc" style="overflow-y:auto;" id="body-hp">
		<HeaDer></HeaDer>
    <div class="space-around bgcc">
      <div class="left">
        <h1 style="font-size:35px">服务机构</h1>
        <h2 style="line-height:40px">为中小微企业、创业者提供导向性、专业性、实践性辅导服务优化小型微型<br/>
          企业创业新环境，支持中小企业健康发展<br/>
          一站式惠企政策信息服务</h2>
      </div>
      <div class="right">
        <div class="title">
          机构账号登录
        </div>
        <div style="margin-top:15px">
          <el-form ref="loginForm" :model="loginForm" :rules="loginRules">
            <el-form-item prop="username">
              <el-input
                placeholder="请输入账号"
                v-model="loginForm.username"
                clearable>
              </el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input
                placeholder="请输入密码"
                v-model="loginForm.password" show-password @keyup.enter.native="handleLogin">
              </el-input>
            </el-form-item>
            <!-- <el-form-item class="flex">
              <el-input
                  placeholder="请输入验证码"
                  v-model="code"
                  style="width:250px"
                  clearable
                  >
              </el-input>
              <div @click="refreshCode()" class="code" title="点击切换验证码">
                <s-identify :identifyCode="identifyCode"></s-identify>
              </div>
            </el-form-item> -->
          </el-form>
          <el-checkbox v-model="checked" @change="chenkUserSeriver" style="margin-top:-20px"></el-checkbox>
          <a v-show="showNo" href="#" style="margin-top:-10px;margin-left:10px;font-size:12px;" @click="openUserSeriver" >我已阅读并同意《见实力工业企业云平台企业版用户协议》</a>
          <a v-show="showYes" href="#" style="margin-top:-10px;margin-left:10px;font-size:12px;color:#1890ff" @click="openUserSeriver" >我已阅读并同意《见实力工业企业云平台企业版用户协议》</a>
        </div>
        <el-button type="primary" plain @click.native.prevent="handleLogin" style="width:361px;margin-top:30px">立即登录</el-button><br/>
        <div class="flex space-between">
          <el-button type="text"  @click="go_zhuci">注册</el-button>
          <el-button type="text"  @click="forgetpassword()">忘记密码</el-button>
        </div>
      </div>
    </div>
		<FooTer></FooTer>
  </div>
</template>

<script>
import HeaDer from '../../components/HomePage/header'
import FooTer from '../../components/HomePage/footer'
import SusPension from '../../components/HomePage/suspension'
import sIdentify from '../../components/HomePage/sIdentify'
import Cookies from "js-cookie";
import { encrypt, decrypt } from '@/utils/jsencrypt'
import axios from "axios";
export default {
	name: "body-hp",
	data () {
		return {
      showNo:true,
      showYes:false,
      loginForm: {
        username: "",
        password: "",
        rememberMe: false,
        code: "",
        uuid: "",
        loginType: null,
      },
      loginRules: {
        username: [
          { required: true, trigger: "blur", message: "请输入您的账号" }
        ],
        password: [
          { required: true, trigger: "blur", message: "请输入您的密码" }
        ],
        //code: [{ required: true, trigger: "change", message: "请输入验证码" }]
      },
      loading: false,
      // 验证码开关
      captchaEnabled: true,
      // 注册开关
      register: false,
      checked: false,//选项卡
      input:'',//账号
      password:'',//密码
      code:'',//验证码
      utcTime: "",
      endTime: "2025-07-31 12:30:59",
      endDate: "2025-07-31 12:30:59",
      defaultTime: "2125-07-15 00:00:00",
      timeServers: [
        "http://quan.suning.com/getSysTime.do",
      ],
      identifyCode: "",
      identifyCodes: ['0','1','2','3','4','5','6','7','8','9','a','b','c','d'], //根据实际需求加入自己想要的字符
      form: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        }
		};
	},
  components: {
		HeaDer,
		FooTer,
		SusPension,
    sIdentify
	},
	methods: {
    //协议跳转
    openUserSeriver(value){
			window.open('/userservice', '_blank');
		},
    //协议跳转
    chenkUserSeriver(value){
      if(value==true){
        this.showNo=false
        this.showYes=true
      }else{
        this.showNo=true
        this.showYes=false
      }
			this.checked = value
		},
	  // // 生成随机数
    // randomNum(min, max) {
    //   max = max + 1
    //   return Math.floor(Math.random() * (max - min) + min);
    // },
    // // 更新验证码
    // refreshCode() {
    //   this.identifyCode = "";
    //   this.makeCode(this.identifyCodes, 4);
    //   console.log('当前验证码:',this.identifyCode);
    // },

    // // 随机生成验证码字符串
    // makeCode(data, len) {
    //   console.log('data, len:', data, len)
    //   for (let i = 0; i < len; i++) {
    //     this.identifyCode += this.identifyCodes[this.randomNum(0, this.identifyCodes.length-1)]
    //   }},
    //   //登录按钮处验证
    // reshCode() {
    //   if (this.code.toLowerCase() !== this.identifyCode.toLowerCase()) {
    //   this.$message.error('请填写正确验证码')
    //       this.refreshCode()
    //       return
    //     }
    //    this.$message.error('账号'+this.input+'密码：'+this.password)

    //   },
      // 忘记密码提示
      forgetpassword() {
        this.$message.error('忘记密码，请联系系统管理员处理！')

      },
      go_zhuci() {
				this.$router.push("/epregister")
			},
      getServerTime() {
      let url = "https://worldtimeapi.org/api/timezone/Asia/Shanghai";
      let xmlhttp = new XMLHttpRequest();
      xmlhttp.open("GET", url, false);
      xmlhttp.send(null);
      return xmlhttp.responseText
    },
    getCode() {
      getCodeImg().then(res => {
        this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
        if (this.captchaEnabled) {
          this.codeUrl = "data:image/gif;base64," + res.img;
          this.loginForm.uuid = res.uuid;
        }
      });
    },
    getTaobaoTime() {
      this.currentTimeServer = 0;
      return new Promise(resolve => {
        this.tryNextTimeServer(resolve);
      });
    },
    tryNextTimeServer(resolve) {
      if (this.currentTimeServer >= this.timeServers.length) {
        this.utcTime = new Date(this.defaultTime);
        resolve(this.utcTime);
        return;
      }

      const currentServer = this.timeServers[this.currentTimeServer];
      this.fetchTimeFromServer(currentServer)
        .then(time => {
          if (!time) {
            throw new Error("Invalid time response");
          }
          this.utcTime = time;
          resolve(this.utcTime);
        })
        .catch(() => {
          this.currentTimeServer++;
          this.tryNextTimeServer(resolve);
        });
    },
    fetchTimeFromServer(server) {
      return new Promise((resolve, reject) => {
        axios
          .get(server, {
            params: {
              _t: new Date().getTime(),
            },
          })
          .then(response => {
            let time;
            if (server.includes("suning")) {
              time = new Date(response.data.sysTime2);
            } else if (server.includes("taobao")) {
              time = new Date(response.data.data.t);
            }
            resolve(time);
          })
          .catch(error => {
            reject(error);
          });
      });
    },
    getCookie() {
      const username = Cookies.get("username");
      const password = Cookies.get("password");
      const rememberMe = Cookies.get('rememberMe')
      this.loginForm = {
        username: username === undefined ? this.loginForm.username : username,
        password: password === undefined ? this.loginForm.password : decrypt(password),
        rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
      };
    },
    handleLogin() {

      this.$refs.loginForm.validate(valid => {
        if (valid) {
          // this.getTaobaoTime().then(() => {
          //   const endDateTime = new Date(this.endDate);
          //   if (this.utcTime > endDateTime) {
          //     return;
          //   }
          //
          // });
          if(this.checked==false){
            this.$message.error("请先阅读并同意用户服务协议！");
          }else{
            this.$store.dispatch('LogOut').then(() => {
            })
            this.loading = true;
            if (this.loginForm.rememberMe) {
              Cookies.set("username", this.loginForm.username, { expires: 30 });
              Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
              Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
            } else {
              Cookies.remove("username");
              Cookies.remove("password");
              Cookies.remove('rememberMe');
            }
            this.loginForm.loginType = "2";//代表当前为机构登录入口
            this.$store.dispatch("Login", this.loginForm).then(() => {
              // var flag = JSON.parse(this.getServerTime());
              // var datetime = flag.datetime.substring(0, 10);
              // if (datetime == null || datetime == "" || datetime == "undefined") {
              //   return;
              // }
              // if (new Date(datetime).getTime() > new Date("2024-10-08").getTime()) {
              //   return;
              // }
              let id = localStorage.getItem("id");
              if (id!==null && id!==undefined){
                this.$router.push("/hdpxd?id="+id);
                localStorage.removeItem("id");
              }else {
                this.$router.push("/index").catch(() => { });
              }
            }).catch(() => {
              this.loading = false;
              if (this.captchaEnabled) {
                this.getCode();
              }
            });
          }
        }
      });
    },
  },
  mounted() {
    //this.refreshCode()
 },
	created() {
    this.getTaobaoTime();
	},
}
</script>

<style lang="scss" scoped>
.flex{
  display: flex;
}
.space-around{
  display: flex;
  justify-content: space-around ;
}
.space-between{
  display: flex;
  justify-content: space-between;
}
.center{
  display: flex;
	justify-content: center;
}
.bgc{
	// background:url(../../assets/images/eplogin/111_02.jpg) no-repeat scroll;
  // background-size:100%;
	// width: 1920rem;
	// height: 100%;
  // .a{
  //   color:white;
  //   .b{
  //     color:white;
  //   }
  // }
}
.bgcc{
	background:url(../../assets/images/eplogin/111_03.jpg) no-repeat scroll;
  background-size:100%;
	width: 1920rem;
	height: 662rem;
  font-size: 14rem;
  padding:20px;
  .left{
    color:white;
    margin-top:120px;
  }
  .right{
      margin-top:60px;
      margin-bottom:50px;
      border-radius: 4px;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      background-color: #E8F5FD;
      // padding:20px;
      padding:40px 20px 20px 20px;

      .title{
        font-weight:bold;
        font-size: 18rem;
        margin-bottom: 30px;

      }
      .code{
        cursor:pointer;
        margin-left:250px;
        margin-top:-36px;
      }
    }
}
/* 回到顶部 end*/
.body-hp{
	height:100%;
	width:100%;
	/* font: 14rem arial; */
	font-size: 14rem;
	font-family:PingFang SC,Microsoft YaHei,Arial,sans-serif;
	color:#676767;
}





</style>
